<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="classes/conndb.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
       <meta name="viewport" content="width=device-width, initial-scale=1">
       <script type="text/javascript" src="js/My97DatePicker/WdatePicker.js"></script>
       <link href="bower_components/bootstrap/dist/css/bootstrap.min.css" type="text/css" rel="stylesheet">
   </head>
   <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
<body>
<div class="container">
  <div class="row">
	<%
		request.setCharacterEncoding("UTF-8");
	    String message_id = request.getParameter("message_id") == null ? "" : request.getParameter("message_id");
		String timekey = request.getParameter("timekey") == null ? "" : request.getParameter("timekey");//默认：全部
		String wkey = request.getParameter("wkey") == null ? "" : request.getParameter("wkey");
			   //wkey = new String(wkey.getBytes("iso-8859-1"),"UTF-8");
		String selectstatus = request.getParameter("selectstatus") == null ? "" : request.getParameter("selectstatus");//默认：未办理
	    String currentPage = request.getParameter("currentPage") == null ? "" : request.getParameter("currentPage");
	    String start_time = request.getParameter("start_time") == null ? "" : request.getParameter("start_time");
	    String end_time = request.getParameter("end_time") == null ? "" : request.getParameter("end_time");
	    String operate_type = request.getParameter("operate_type") == null ? "" : request.getParameter("operate_type");
	    //operate_type = new String(operate_type.getBytes("iso-8859-1"),"UTF-8");
	    
	    String messager_name= "";
	    String messager_sex= "";
	    String messager_phone= "";
	    String messager_email= "";
	    String messager_address= "";
	    String submit_time= "";
	    String title ="";
	    String content = "";
	    String status = "";
	    String is_public = "";
	    String answer_content= "";
	    String answer_time ="";
	%>
	<%
     PreparedStatement ps= null;
     Connection con =null;
     ResultSet rs=null;

	 try {
			con = getConnection();
			String sql = "select t1.*,t2.content as answer_content,t2.operate_time as answer_time from cms_public_comment t1 left join cms_reply_comment t2 on t1.message_id = t2.message_id where t1.message_id=?";
	    	ps=con.prepareStatement(sql);
			ps.setObject(1, message_id);
	    	rs=ps.executeQuery();
	    	
	    	while (rs.next()) {
	    		messager_name= rs.getString("messager_name")== null ? "" : rs.getString("messager_name");
	    		messager_sex= rs.getString("messager_sex")== null ? "" : rs.getString("messager_sex").replace("1", "男").replace("0", "女");
	    		messager_phone= rs.getString("messager_phone")== null ? "" : rs.getString("messager_phone");
	    		messager_email= rs.getString("messager_email")== null ? "" : rs.getString("messager_email");
	    		submit_time= rs.getString("operate_time")== null ? "" : rs.getString("operate_time").toString().substring(0,rs.getTimestamp("operate_time").toString().lastIndexOf(".0"));
	    		title= rs.getString("title")== null ? "" : rs.getString("title");
	    		content= rs.getString("content")== null ? "" : rs.getString("content");
	    		status= rs.getString("status")== null ? "" : rs.getString("status").replace("1", "未办理").replace("2", "已回复").replace("3", "已完成");
	    		is_public= rs.getString("is_public")== null ? "" : rs.getString("is_public").replace("1", "是").replace("0", "否");
	    		answer_content= rs.getString("answer_content")== null ? "" : rs.getString("answer_content");
	    		answer_time= rs.getTimestamp("answer_time") == null ? "" : rs.getTimestamp("answer_time").toString().substring(0,rs.getTimestamp("answer_time").toString().lastIndexOf(".0"));
	    	}
	    }catch(Exception e){
			e.printStackTrace();
		}finally{
			closeConn(con,ps,rs);
		}
	%>
		<table class="table table-responsive" width="100%" border="0" cellspacing="0" cellpadding="0">
			<tbody>
				<tr>
					<th style="width:100px;">填写人：</th>
					<td><div class="col-xs-4"><%=messager_name %></div></td>
				</tr>
				<tr>
					<th>性    别：</th>
					<td><div class="col-xs-4"><%=messager_sex %></div></td>
				</tr>
				<tr>
					<th>电    话：</th>
					<td><div class="col-xs-4"><%=messager_phone %></div></td>
				</tr>
				<tr>
					<th>联系地址：</th>
					<td><div class="col-xs-4"><%=messager_address %></div></td>
				</tr>
				<tr>
					<th>Email地址：</th>
					<td><div class="col-xs-4"><%=messager_email %></div></td>
				</tr>
				<tr>
					<th>填写时间：</th>
					<td><div class="col-xs-4">
							<input class="form-control" style="display:inline;width:200px;height:25px;" type="text" id="submit_time" readonly="readonly" value="<%=submit_time %>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d %H%m:%s'})" />
						</div>
					</td>
				</tr>
				<tr>
					<th>标	题：</th>
					<td><div class="col-xs-4"><%=title %></div></td>
				</tr>
				<tr>
					<th>留言内容：</th>
					<td><div class="col-xs-4"><%=content %></div></td>
				</tr>
				<tr>
					<th>状态：</th>
					<td><div class="col-xs-4"><%=status %></div></td>
				</tr>
				<tr>
					<th>是否公开：</th>
					<td>
						<div class="col-xs-4">
							<select id="is_public" class="form-control" style="display:inline;width:70px;height:30px;">
								<option value="1" <%if(is_public.equals("是")) out.print("selected='selected'"); %>>是</option>
								<option value="0" <%if(is_public.equals("否")) out.print("selected='selected'"); %>>否</option>
							</select>
						</div>
					</td>
				</tr>
				<tr>
					<th>回复内容：</th>
					<td>
						<div class="col-xs-4">
							<textarea id="answer_content" class="form-control" style=" height: 100px; width: 400px;"><%=answer_content %></textarea>
						</div>
					</td>
				</tr>
				<tr>
					<th>回复时间：</th>
					<td>
						<div class="col-xs-4">
							<input class="form-control" style="display:inline;width:200px;height:25px;" type="text" id="answer_time" readonly="readonly" value="<%=answer_time %>" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d %H%m:%s'})" />
						</div>
					</td>
				</tr>
				<tr>
					<th colspan="2">
					   <input type="button" class="btn btn-primary" id="sure" value="更新" />
					   <input type="hidden" id="message_id" value="<%=message_id%>" />
					   <input type="hidden" id="timekey" value="<%=timekey%>"/>  
               		   <input type="hidden" id="wkey" value="<%=wkey%>"/>  
               		   <input type="hidden" id="selectstatus" value="<%=selectstatus%>"/>
               		   <input type="hidden" id="start_time" value="<%=start_time%>"/>
               		   <input type="hidden" id="end_time" value="<%=end_time%>"/> 
               		   <input type="hidden" id="operate_type" value="<%=operate_type%>"/>           
               		   <input type="hidden" id="currentPage" value="<%=currentPage%>"/> 
					</th>
				</tr>
			</tbody>
		</table>
	</div>
        </div>

        
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery-1.8.0.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
	<script>
$(document).ready(function() {
		
//提交	
	$("#sure").click(function() {
		var message_id = $("#message_id").val();
	    var timekey =  $("#timekey").val();
	    var wkey =  $("#wkey").val();
	    var selectstatus =  $("#selectstatus").val();
	    var start_time = $("#start_time").val();
	    var end_time = $("#end_time").val();
	    var operate_type = $("#operate_type").val();
	    var currentPage =  $("#currentPage").val();
		
		var is_public = $("#is_public").val();
		var answer_content = $("#answer_content").val();
		var answer_time = $("#answer_time").val();
		var submit_time = $("#submit_time").val();
		
		$.post("doedit.jsp", {
			message_id:message_id,
			is_public:is_public,
			answer_content:answer_content,
			answer_time:answer_time,
			submit_time:submit_time
		}, function(data, status) {
			//var obj=JSON.parse(data);写出返回类型json时，该语句可省略
			if (data.operate_status == "1") {
				alert("修改成功！");
				window.location.href="list.jsp?timekey="+timekey+"&wkey="+wkey+"&selectstatus="+selectstatus+"&start_time="+start_time+"&end_time="+end_time+"&operate_type="+operate_type+"&currentPage="+currentPage+"&t="+new Date().getTime();
			} else {
				alert("修改失败！");
			}
		}, "json");
	});
});
</script>
</body>
</html>

